package pe.edu.upc.dew.cobranzas.dao;


import java.sql.*;

/**
 *
 * @author Lennon Shimokawa
 */
public class ConnectionUtils {

    private static final String URL ="jdbc:sqlserver://localhost:1433;databaseName=cobranzas;user=sa;password=P4ssw0rD;";

    public static Connection getConnection() {
        Connection connection = null;
        try {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
            connection = DriverManager.getConnection(URL);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return connection;
    }

    public static void closeConnection(Connection connection) {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public static void closeStatement(Statement statement) {
        try {
            if (statement != null) {
                statement.close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public static void closeResultSet(ResultSet resultSet) {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
}





